//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package messages;

import common.ByteStream;
import common.StringUtils;

public abstract class Base {
  public ByteStream writeStream;
  public ByteStream readStream;
  public boolean isDecoded = false;
  protected int messageID = 0;
  protected int version = 14413;

  public Base(int id) {
    this.messageID = id;
    this.writeStream = new ByteStream(100);
    this.readStream = null;
  }

  public int getVersion() {
    return this.version;
  }

  public int getId() {
    return this.messageID;
  }

  public byte[] getHeader(int leadingSpace) {
    byte[] hdr = new byte[7];
    hdr[0] = (byte)(this.messageID >> 8);
    hdr[1] = (byte)(this.messageID >> 0);
    int len = this.writeStream.getLength();
    len += leadingSpace;
    hdr[2] = (byte)(len >> 16);
    hdr[3] = (byte)(len >> 8);
    hdr[4] = (byte)(len >> 0);
    hdr[5] = (byte)(this.version >> 8);
    hdr[6] = (byte)(this.version >> 0);
    return hdr;
  }

  public byte[] getHeader() {
    byte[] hdr = new byte[7];
    hdr[0] = (byte)(this.messageID >> 8);
    hdr[1] = (byte)(this.messageID >> 0);
    int len = this.writeStream.getLength();
    hdr[2] = (byte)(len >> 16);
    hdr[3] = (byte)(len >> 8);
    hdr[4] = (byte)(len >> 0);
    hdr[5] = (byte)(this.version >> 8);
    hdr[6] = (byte)(this.version >> 0);
    return hdr;
  }

  public byte[] getContent() {
    this.encode(this.writeStream);
    return this.writeStream.getCopyOfByteArray();
  }

  public void setVersion(int version) {
    this.version = version;
  }

  public String toString() {
    String msg = String.format("Message: %02x %02x, Version: %02x %02x\n", new Object[]{Integer.valueOf(this.messageID >> 8 & 255), Integer.valueOf(this.messageID & 255), Integer.valueOf(this.version >> 8 & 255), Integer.valueOf(this.version & 255)});
    if(this.readStream != null) {
      msg = msg + StringUtils.dumpBytes(this.readStream.getCopyOfByteArray());
    }

    return msg;
  }

  public abstract void encode(ByteStream var1);

  public abstract void decode(ByteStream var1);
}
